﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class WebUserControl_CtrSettingViewReport : System.Web.UI.UserControl
{
    BCDataCenter.DataAccessLayer.DAL dt;
    static string UserName="",error="";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            UserName = Session["UserName"].ToString();
            try
            {
                dt = new BCDataCenter.DataAccessLayer.DAL();
                DataSet ds = new DataSet();
                ds = dt.MyExecuteReader(ref error, "SELECT 0 as Sitecode,'Chọn TTPP' as sitename FROM mis UNION SELECT Sitecode, sitename FROM mis WHERE     (Active = 1)", CommandType.Text);
                DropDownList1.DataSource = ds.Tables[0];
                DropDownList1.DataTextField = "sitename";
                DropDownList1.DataValueField = "sitecode";
                DropDownList1.DataBind();
            }
            catch (Exception ex)
            {
                uscMsgBox1.AddMessage(ex.Message, uscMsgBox.enmMessageType.Error);
            }
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        dt = new BCDataCenter.DataAccessLayer.DAL();
        string sqlstr = "";
        int row = GridView1.Rows.Count;
        for (int i = 0; i < row; i++)
        {
            try
            {
                string salespkey = GridView1.Rows[i].Cells[1].Text.ToString();
                CheckBox cb = (CheckBox)(GridView1.Rows[i].FindControl("CheckBox1"));
                if (cb.Checked == true)
                {
                    sqlstr = "update ARSALESP set ViewReport =1 where salesp_key ='" + salespkey + "'";
                }
                else
                {
                    sqlstr = "update ARSALESP set ViewReport =0 where salesp_key ='" + salespkey + "'";
                }
                dt.MyExecuteNonQuerys(sqlstr, CommandType.Text, ref error);
            }
            catch (Exception ex)
            {
                uscMsgBox1.AddMessage(ex.Message, uscMsgBox.enmMessageType.Error);
            }
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        dt = new BCDataCenter.DataAccessLayer.DAL();
        DataSet ds = new DataSet();
        string sitecode = DropDownList1.SelectedValue.ToString();
        try
        {
            ds = dt.MyExecuteQuery(ref error, "GetBumOver", CommandType.StoredProcedure, new System.Data.SqlClient.SqlParameter("@sitecode", sitecode));
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();
        }
        catch (Exception ex)
        {
            uscMsgBox1.AddMessage(ex.Message, uscMsgBox.enmMessageType.Error);
        }
    }
}
